﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Net;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Diagnostics;
using System.Xml.Linq;

namespace InfoPlayas
{
    /// <summary>
    /// Summary description for InfoPlayas
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class InfoPlayas : System.Web.Services.WebService
    {
       
        [WebMethod]
        public string GetInfoPlaya(String playa)
        {
            //

            Conexion cn = new Conexion();

            string html = cn.getContent("http://www.mma.es/dinamicas/guia_playas/?" + playa);

            PlayasParse parser = new PlayasParse();
          
            parser.extractTablePlayas(html);
            return (parser.createXMLPlayas());
        }
        [WebMethod]
        public string ListaMunicipios(string provincia)
        {
            Conexion cn = new Conexion();
            string html;
            if (provincia.ToUpper() == "BARCELONA")
            {
                //Los de barcelona son especiales.
                html = cn.getContent(string.Format("http://www.mma.es/portal/secciones/aguas_marinas_litoral/guia_playas/{0}/{0}_prov2.htm", provincia));
                html = cn.getContent(string.Format("http://www.mma.es/portal/secciones/aguas_marinas_litoral/guia_playas/{0}/{0}_prov3.htm", provincia));

            }
            else
            {

                html = cn.getContent(string.Format("http://www.mma.es/portal/secciones/aguas_marinas_litoral/guia_playas/{0}/{0}_prov.htm", provincia));
            }
              PlayasParse parser = new PlayasParse();
              parser.extractTableMunicipiosListaPlayas(html,false);
              return (parser.createXMLMunicipios());

          
        }

        [WebMethod]
        public string ListaPlayas(string provincia, string municipio)
        {
            Conexion cn = new Conexion();

            string html = cn.getContent(string.Format("http://www.mma.es/portal/secciones/aguas_marinas_litoral/guia_playas/{0}/{1}", provincia, municipio));
            PlayasParse parser = new PlayasParse();
            StringBuilder element = parser.extractTableMunicipiosListaPlayas(html,true);
            return (parser.createXMLListaPlayas());
           
        }

     
    }
}
